function [objval]=evaluate_obj(piSet, SSet, yl, yr, lambdal, lambdar, alpha)

% objective function evaluation in C3E

N=size(SSet,1);

term11=sum(sum(piSet.*log(piSet)));
term12=sum(sum(yr.*log(yr)));
gradyr=1+log(yr);
term13=sum(sum(piSet.*gradyr));
term14=sum(sum(yr.*gradyr));
term1=term11-term12-term13+term14;


Srow=sum(SSet,2)-[diag(SSet)];
Scol=[sum(SSet,1)-diag(SSet)']';
phiyl=sum(yl.*log(yl),2);
phiyr=sum(yr.*log(yr),2);
term21=Srow'*phiyl;
term22=Scol'*phiyr;
prodylgradyr=yl*gradyr';
diagval=diag(prodylgradyr);
prodylgradyr=prodylgradyr-diag(diagval);
term23=sum(sum(SSet.*prodylgradyr));
prodyrgradyr=yr*gradyr';
diagval=diag(prodyrgradyr);
term24=Scol'*diagval;
term2=term21-term22-term23+term24;



% term2=0;
% for i=1:N
%  for j=1:N
%   term21=yl(i,:)*(log(yl(i,:)))';
%   term22=yr(j,:)*(log(yr(j,:)))';
%   term23=(yl(i,:)-yr(j,:))*(1+log(yr(j,:)))';
%   term2=term2+SSet(i,j)*[term21-term22-term23];
%  end
% end





term31=lambdal'*sum(piSet.*log(piSet),2);
term32=lambdal'*sum(yr.*log(yr),2);
term33=lambdal'*sum(yl.*gradyr,2);
term34=lambdal'*sum(yr.*gradyr,2);
term3=term31-term32-term33+term34;

objval=term1+alpha*term2+term3;







